WIDTH = 300
HEIGHT = 300

BACK_COLOR = (0, 0, 127)
RC_COLOR = (0, 200, 0)

x = 0
y = 100
w = 100
h = 100
s = 2

def on_key_down(key):
    if key == keys.ESCAPE:
        quit()
'''
def on_mouse_move(pos)
    print("mouse_move",pos)
'''
def on_mouse_down(pos):
    print("mouse_down", pos)

def on_mouse_up(pos):
    print("mouse_up", pos)

def draw_rect(x, y, w, h):
    rc = Rect((x - w // 2, y - h // 2), (w, h))
    screen.draw.filled_rect(rc, RC_COLOR)
    return 1

def update():
    global x
    global s
    x += s
    if x - w // s > WIDTH:
        s=-2
    elif x - w//s < WIDTH/5 and s==-2:
        s=2
def draw():
    screen.clear()
    screen.fill(BACK_COLOR)
    draw_rect(x, y, w, h)